package com.example.templateapp.util.http

import android.app.Application
import okhttp3.OkHttpClient
import rxhttp.wrapper.param.RxHttp
import java.util.concurrent.TimeUnit

object RxHttpManager {

     fun init(context: Application, isDebug: Boolean) {
//        var file = File(context.externalCacheDir,"http_cookie")
//        var trustAllCert = X509TrustManagerImpl()
//        var sslSocketFactoryImpl = SSLSocketFactoryImpl(trustAllCert)

         var httpClient = OkHttpClient.Builder()
//            .cookieJar(CookieStore(file))
             .connectTimeout(10, TimeUnit.SECONDS)
             .readTimeout(10, TimeUnit.SECONDS)
             .writeTimeout(10, TimeUnit.SECONDS)
//            .sslSocketFactory(sslSocketFactoryImpl,trustAllCert)
            .hostnameVerifier { hostname, session -> true }
            .build()

         RxHttp.init(httpClient, isDebug)



/*        //设置缓存策略，非必须
        val cacheFile = File(context.externalCacheDir, "RxHttpCache")
        RxHttpPlugins.setCache(
            cacheFile,
            1000 * 100.toLong(),
            CacheMode.REQUEST_NETWORK_FAILED_READ_CACHE
        )
        RxHttpPlugins.setExcludeCacheKeys("time") //设置一些key，不参与cacheKey的组拼*/


    }
}